// pages/tap_map/tap_map.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    longitude:'118.8921',
    latitude:'31.32751',
    scale:'14',   
    addressName: '',
    textData: '',
    locationAddress:'',
    name:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  show_map:function(){
    let that = this;   

    wx.chooseLocation({
      // latitude: that.data.longitude,
      // longitude: that.data.latitude,
      success(res_location) {
        
        that.setData({
          // hasLocation: true,
          // location: formatLocation(res.longitude, res.latitude),
          locationAddress: res_location.address,
          longitude: res_location.longitude,
          latitude: res_location.latitude,
          name: res_location.name
        });
      }
    })
  },

  onReady: function (e) {
    // this.mapCtx = wx.createMapContext('map')
  },
  mapclick: function () {
    var that = this;
   
    wx.chooseLocation({
      success: function (res) {       
        var user_longitude = res.longitude;
        var user_lagitude = res.latitude;
        var user_address = res.address;
        var nowAddress = {};
        nowAddress["name"] = res.name;
        nowAddress["desc"] = res.address;
        that.setData({
          lagitude: user_lagitude,
          longitude: user_longitude,
          addressName: user_address,
          textData: nowAddress,
        });

        
        //移动marker
        that.mapCtx.moveToLocation({
          lagitude: user_lagitude,
          longitude: user_longitude,
        });
      },
      fail: function (res) {
        console.log("点击地图fail:" + JSON.stringify(res));
      },
      complete: function (res) {        // complete
        console.log("点击地图complete:" + JSON.stringify(res));
      }
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})